# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def removeNthFromEnd(self, head: ListNode, n: int) -> ListNode:
        
        a = ListNode(0, head) 
        b = a
        c = a
        for i in range(n+1):
            a = a.next

        while a:
            a = a.next
            b = b.next
        b.next = b.next.next
        return c.next